class Solution:
    def maxAbsoluteSum(self, nums: list) -> int:
        maxPre = 0
        minPre = 0
        cur = 0
        res = 0
        for i in range(len(nums)):
            cur += nums[i]
            if cur > 0:
                absVal = abs(cur - minPre)
            elif cur < 0:
                absVal = abs(cur - maxPre)
            else:
                absVal = max(abs(minPre), abs(maxPre))
            minPre = min(cur, minPre)
            maxPre = max(cur, maxPre)
            res = max(absVal, res)

        return res
